package com.klangner.math.transform;

import junit.framework.TestCase;

import com.klangner.math.ast.Node;
import com.klangner.math.parser.ExpressionParser;
import com.klangner.math.transform.AddTransform;

public class AddTransTestCase extends TestCase {

	/** 
	 * Test data. Format:
	 * input => expected output 
	 */
	private static final String[][] testData = {
		{"2*3", "2*3"},
		{"2+3", "5"},
		{"2+3+14", "19"},
		{"3-4", "-1"},
		{"-3-4", "-7"},
		{"2-3+4", "3"},
		{"2-3--4", "3"},
		{"2+1-3+4", "4"},
		{"x+x", "2*x"},
		{"-x-x", "-2*x"},
		{"x-x", "0"},
		{"x+3*x", "4*x"},
		{"x-3*x", "-2*x"},
		{"3*x+x", "4*x"},
		{"a+2*x-x-x", "a"},
		{"2*x+3*x", "5*x"},
		{"2*x^2+3*x^2", "5*x^2"}
	};
	
	
	public void testData() {
		Node document;
		Node result;
		ExpressionParser parser = new ExpressionParser();
		AddTransform trans = new AddTransform();
		
		for(int i = 0; i < testData.length; i++){
		
			document = parser.parse( testData[i][0] );
			result = document.transform(trans);
			assertEquals("Input: " + testData[i][0], testData[i][1], result.toString());
		}
	}

}
